package com.hao.editorview.model;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建表情图
 */
public class EmojiUtils {

    private static class EmojiUtilsHolder {
        static EmojiUtils emojiUtils = new EmojiUtils();
    }

    public static EmojiUtils getInstance() {
        return EmojiUtilsHolder.emojiUtils;
    }

    private final String emoji[] = {
            "\\ud83d\\ude04"
            , "\\ud83d\\ude0a"
            , "\\ud83d\\ude03"
            , "\\ud83d\\ude09"
            , "\\ud83d\\ude0d"
            , "\\ud83d\\ude18"
            , "\\ud83d\\ude1a"
            , "\\ud83d\\ude33"
            , "\\ud83d\\ude0c"
            , "\\ud83d\\ude01"
            , "\\ud83d\\ude1c"
            , "\\ud83d\\ude1d"
            , "\\ud83d\\ude12"
            , "\\ud83d\\ude0f"
            , "\\ud83d\\ude13"
            , "\\ud83d\\ude14"
            , "\\ud83d\\ude1e"
            , "\\ud83d\\ude16"
            , "\\ud83d\\ude25"
            , "\\ud83d\\ude30"
            , "\\ud83d\\ude28"
            , "\\ud83d\\ude23"
            , "\\ud83d\\ude22"
            , "\\ud83d\\ude2d"
            , "\\ud83d\\ude02"
            , "\\ud83d\\ude32"
            , "\\ud83d\\ude31"
            , "\\ud83d\\ude20"
            , "\\ud83d\\ude21"
            , "\\ud83d\\ude2a"
            , "\\ud83d\\ude37"
            , "\\ud83d\\udc7f"
            , "\\ud83d\\udc7d"
            , "\\ud83d\\udc9b"
            , "\\ud83d\\udc99"
            , "\\ud83d\\udc9c"
            , "\\ud83d\\udc97"
            , "\\ud83d\\udc9a"
            , "\\ud83d\\udc94"
            , "\\ud83d\\udc93"
            , "\\ud83d\\udc98"
            , "\\ud83d\\udca2"
            , "\\ud83d\\udca4"
            , "\\ud83d\\udca8"
            , "\\ud83d\\udca6"
            , "\\ud83d\\udd25"
            , "\\ud83d\\udca9"
            , "\\ud83d\\udc4d"
            , "\\ud83d\\udc4e"
            , "\\ud83d\\udc4c"
            , "\\ud83d\\udc4a"
            , "\\ud83d\\udc4b"
            , "\\ud83d\\udc50"
            , "\\ud83d\\udc46"
            , "\\ud83d\\udc47"
            , "\\ud83d\\udc49"
            , "\\ud83d\\udc48"
            , "\\ud83d\\ude4c"
            , "\\ud83d\\ude4f"
            , "\\ud83d\\udc4f"
            , "\\ud83d\\udcaa"
            , "\\ud83d\\udeb6"
            , "\\ud83d\\udc6b"
            , "\\ud83d\\udc83"
            , "\\ud83d\\udc6f"
            , "\\ud83d\\ude46"
            , "\\ud83d\\ude45"
            , "\\ud83d\\udc81"
            , "\\ud83d\\ude47"
            , "\\ud83d\\udc8f"
            , "\\ud83d\\udc91"
            , "\\ud83d\\udc86"
            , "\\ud83d\\udc87"
            , "\\ud83d\\udc85"
            , "\\ud83d\\udc66"
            , "\\ud83d\\udc67"
            , "\\ud83d\\udc69"
            , "\\ud83d\\udc68"
            , "\\ud83d\\udc76"
            , "\\ud83d\\udc75"
            , "\\ud83d\\udc74"
            , "\\ud83d\\udc71"
            , "\\ud83d\\udc72"
            , "\\ud83d\\udc73"
            , "\\ud83d\\udc77"
            , "\\ud83d\\udc6e"
            , "\\ud83d\\udc7c"
            , "\\ud83d\\udc78"
            , "\\ud83d\\udc82"
            , "\\ud83d\\udc80"
            , "\\ud83d\\udc63"
            , "\\ud83d\\udc8b"
            , "\\ud83d\\udc44"
            , "\\ud83d\\udc42"
            , "\\ud83d\\udc40"
            , "\\ud83d\\udc43"
            , "\\ud83d\\udc31"
            , "\\ud83d\\udc36"
            , "\\ud83d\\udc2d"
            , "\\ud83d\\udc39"
            , "\\ud83d\\udc30"
            , "\\ud83d\\udc3a"
            , "\\ud83d\\udc38"
            , "\\ud83d\\udc2f"
            , "\\ud83d\\udc28"
            , "\\ud83d\\udc3b"
            , "\\ud83d\\udc37"
            , "\\ud83d\\udc2e"
            , "\\ud83d\\udc17"
            , "\\ud83d\\udc35"
            , "\\ud83d\\udc12"
            , "\\ud83d\\udc34"
            , "\\ud83d\\udc0e"
            , "\\ud83d\\udc2b"
            , "\\ud83d\\udc11"
            , "\\ud83d\\udc18"
            , "\\ud83d\\udc0d"
            , "\\ud83d\\udc26"
            , "\\ud83d\\udc24"
            , "\\ud83d\\udc14"
            , "\\ud83d\\udc27"
            , "\\ud83d\\udc1b"
            , "\\ud83d\\udc19"
            , "\\ud83d\\udc20"
            , "\\ud83d\\udc1f"
            , "\\ud83d\\udc33"
            , "\\ud83d\\udc2c"
            , "\\ud83d\\udc90"
            , "\\ud83d\\udc1a"
            , "\\ud83d\\udc9d"
            , "\\ud83d\\udc7b"
            , "\\ud83d\\udd14"
            , "\\ud83d\\udcbf"
            , "\\ud83d\\udcc0"
            , "\\ud83d\\udcf7"
            , "\\ud83d\\udcbb"
            , "\\ud83d\\udcfa"
            , "\\ud83d\\udcf1"
            , "\\ud83d\\udce0"
            , "\\ud83d\\udcbd"
            , "\\ud83d\\udcfc"
            , "\\ud83d\\udd0a"
            , "\\ud83d\\udce2"
            , "\\ud83d\\udce3"
            , "\\ud83d\\udcfb"
            , "\\ud83d\\udce1"
            , "\\ud83d\\udd0d"
            , "\\ud83d\\udd13"
            , "\\ud83d\\udd12"
            , "\\ud83d\\udd11"
            , "\\ud83d\\udd28"
            , "\\ud83d\\udca1"
            , "\\ud83d\\udcf2"
            , "\\ud83d\\udce9"
            , "\\ud83d\\udceb"
            , "\\ud83d\\udcee"
            , "\\ud83d\\udec0"
            , "\\ud83d\\udebd"
            , "\\ud83d\\udcba"
            , "\\ud83d\\udcb0"
            , "\\ud83d\\udd31"
            , "\\ud83d\\udeac"
            , "\\ud83d\\udca3"
            , "\\ud83d\\udd2b"
            , "\\ud83d\\udc8a"
            , "\\ud83d\\udc89"
            , "\\ud83d\\udc7e"
            , "\\ud83d\\udcdd"
            , "\\ud83d\\udcd6"
            , "\\ud83d\\udc5f"
            , "\\ud83d\\udc61"
            , "\\ud83d\\udc60"
            , "\\ud83d\\udc62"
            , "\\ud83d\\udc55"
            , "\\ud83d\\udc54"
            , "\\ud83d\\udc57"
            , "\\ud83d\\udc58"
            , "\\ud83d\\udc59"
            , "\\ud83d\\udc51"
            , "\\ud83d\\udc52"
            , "\\ud83d\\udcbc"
            , "\\ud83d\\udc5c"
            , "\\ud83d\\udc84"
            , "\\ud83d\\udc8d"
            , "\\ud83d\\udc8e"
            , "\\ud83d\\udc92"
            , "\\ud83d\\uddfc"
            , "\\ud83d\\uddfb"
            , "\\ud83d\\uddfd"
            , "\\ud83d\\udea2"
            , "\\ud83d\\udea4"
            , "\\ud83d\\ude80"
            , "\\ud83d\\udeb2"
            , "\\ud83d\\ude99"
            , "\\ud83d\\ude97"
            , "\\ud83d\\ude95"
            , "\\ud83d\\ude8c"
            , "\\ud83d\\ude93"
            , "\\ud83d\\ude92"
            , "\\ud83d\\ude91"
            , "\\ud83d\\ude9a"
            , "\\ud83d\\ude83"
            , "\\ud83d\\ude89"
            , "\\ud83d\\ude84"
            , "\\ud83d\\ude85"
            , "\\ud83d\\udea5"
            , "\\ud83d\\udea7"
            , "\\ud83d\\udd30"
            , "\\ud83d\\ude8f"
            , "\\ud83d\\udc88"
    };

    private List<String> emojiStr;

    public List<String> getEmojiStr() {
        if (emojiStr == null || emojiStr.size() <= 0)
            emojiStr = creatEmoji(emojiStr);
        return emojiStr;
    }

    private List<String> creatEmoji(List<String> list) {
        list = new ArrayList<>();
        for (int i = 0; i < emoji.length; i++)
            list.add(ascii2native(emoji[i]));
        return list;
    }

    public static String ascii2native(String ascii) {
        int n = ascii.length() / 6;
        StringBuilder sb = new StringBuilder(n);
        for (int i = 0, j = 2; i < n; i++, j += 6) {
            String code = ascii.substring(j, j + 4);
            char ch = (char) Integer.parseInt(code, 16);
            sb.append(ch);
        }
        return sb.toString();
    }
}
